package com.example.demo.bean.queue.disruptor;

import com.lmax.disruptor.EventTranslatorVararg;
import com.lmax.disruptor.RingBuffer;

/**
 * 使用translator方式生产者
 */
public class OutputEventProducer {
    private final RingBuffer<OutputEvent> ringBuffer;

    public OutputEventProducer(RingBuffer<OutputEvent> ringBuffer){
        this.ringBuffer = ringBuffer;
    }

    public void onData(String data){
        long sequence = ringBuffer.next();
        try {
            OutputEvent order = ringBuffer.get(sequence);
            order.setId(data);
        } finally {
            ringBuffer.publish(sequence);
        }
    }

}
